import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
  ScrollView,
  Image,
  Animated,
  DeviceEventEmitter,
  Platform,
  NativeAppEventEmitter,
  TouchableOpacity,
  Modal,
  Button,
  NativeModules
} from 'react-native';
const {CommonUtils} = NativeModules;
import styles from './indexStyle';
import api from '../../services/api';
import Touch from '../global/Touch';
import { Navigation } from '../global/navigation/index';
import VersionModal from './versionUpdate';
import * as config from '../../constants/apiConfig';
import OrderRewardDialog from './orderRewardDialog';
import ShopContractDialog from './shopContractDialog';
import EasemobChat from '../global/EasemobChat';
import LoadingTip from '../global/LoadingTip';

let windowHeight = 80;
class Account extends Component {
    constructor(props) {
		super(props);

		this.state = {
            order_count:0,
            order_reward:0,
            order_obj_price:0,
            disabled: false,
            balance:0,
            shopAllBalance:0,
            scrollY: new Animated.Value(0),
            reward_score: 0,
            rank: '0/0',
            flag_ardour: 0,
            flag_capable:0,
            flag_witty:0,
            flag_intimate:0,
            notapprovedcount: 0,
            deliveryCount:0,
            showModal:false,
            lastVersionInfo:{},
            showOrderRewardDialog:false,
            isClickOrderRewardTab:false,
            loadingShow:false,
            contractInfo:{},
            showShopContractDialog:false,
		};


		this.props.navigator.setOnNavigatorEvent(this._onNavigatorEvent.bind(this));
	}

    _onNavigatorEvent(event){

    	if (event.id === 'didAppear') { //出现时
            this._getOrderSummary();
            this._getHKSummary();
            this._getNotApprovedCount();
            this._getShowingTab();

            let { session } = this.props;
            
            let hk_role = session && session.user && session.user.role;
            if(hk_role == 0){//物业管家
                this.loadDeliveryApproved();
            }
            if (session && session.user && session.user.isShop == 1) {
                this._getShopBalance();
                this._getContractInfo();
            }
    	}
    }

    loadApproved(){
        this._getNotApprovedCount();
    }

    componentDidMount() {
        //去除跑单奖励弹窗
        // //先弹跑单有奖弹窗再提示更新
        // let {session} = this.props;
        // if (session && session.user && session.user.role != 1 && session.user.isShop != 1 && session.user.productKey == "HeChang") {
        //     NativeModules.SharedPreferences.getBoolean("isClickOrderRewardTab",(data) =>{
        //         this.setState({isClickOrderRewardTab:data})
        //     })
        //     NativeModules.SharedPreferences.getBoolean("isShowRecordDialog",(data) => {
        //         if (data == false) {//非消息中心、且非商户、并且未展示过
        //             this.setState({
        //                 showOrderRewardDialog:true,
        //             })
        //         }else{
        //             //检查版本更新
        //             CommonUtils.getVersion(async (num) =>{ 
        //                 let res = await api.post('/version/android/last')
        //                 console.log(res,'version/android/last')
        //                 if (res.cd == 0&&res.data.id > num) {
        //                     this.setState({lastVersionInfo:res.data},() => {
        //                         this.setState({showModal:true})
        //                     })
        //                 }
        //             })  
        //         }
        //     })
        // }else{
        //     if (session.user.productKey == "HeChang") {//只有和昌管家APP才能自动更新
        //         //检查版本更新
        //         CommonUtils.getVersion(async (num) =>{ 
        //             let res = await api.post('/version/android/last')
        //             console.log(res,'version/android/last')
        //             if (res.cd == 0&&res.data.id > num) {
        //                 this.setState({lastVersionInfo:res.data},() => {
        //                     this.setState({showModal:true})
        //                 })
        //             }
        //         })
        //     }
            
        // }
        let {session} = this.props;
        // if (session.user.productKey == "HeChang") {//只有和昌管家APP才能自动更新
            //检查版本更新
            CommonUtils.getVersion(async (num) =>{ 
                let res = await api.post('/version/android/last')
                console.log(res,'version/android/last')
                if (res.cd == 0&&res.data.versionNum > num) {
                    this.setState({lastVersionInfo:res.data},() => {
                        this.setState({showModal:true})
                    })
                }
            })
        // }    
        //判断当前登录的账号和当前APP所属的公众号平台是否一致，不一致就退出账号  
        let {productKey} = session.user;
        console.log('account/index/componentDidMount/productKey=',productKey);
        if (productKey) {
            let webBaseUrl = config.WEB_BASE_URL;
            switch(webBaseUrl) {
                case config.HC_WEB_BASE_URL:
                    if (productKey != "HeChang") {
                        this._logout();
                    }
                    break;
                case config.HLZ_WEB_BASE_URL:
                    if (productKey != "HuLiZhan") {
                        this._logout();
                    }
                    break;
                case config.LXS_WEB_BASE_URL:
                    if (productKey != "LiXiaoShuang") {
                        this._logout();
                    }
                    break;
                case config.CYJ_WEB_BASE_URL:
                    if (productKey != "ChangYangJi") {
                        this._logout();
                    }
                    break;

            }
        }else{

        }


        let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
        this._subcribAccount = Emitter.addListener('approve.onload', this.loadApproved.bind(this));
        this._subcribDelivery = Emitter.addListener('delivery.count.onload', this.loadDeliveryApproved.bind(this));
        this._updateSession = Emitter.addListener('update_session',this.updateSession.bind(this));
        if (session.user.isShop == 1 ) {
            this._updateSignContract = Emitter.addListener('update_sign_contract',this._getContractInfo.bind(this));
        }
	}

    updateSession(){
        console.log('test',"---------------------updateSession");
        let { session, actions, dispatch } = this.props;
        dispatch(actions.session.session_change({
            ticket:session.stoken,
            userId:session.user.id,
            reload: false,
            group:session.user.group
        }));
    }

    //退出
    async _logout(){
        this.setState({loadingShow:true,showModal:false,showOrderRewardDialog:false});
        let { session } = this.props;
        let user_role = session && session.user.role;
        if(user_role == 1 || (user_role == 0 && session.user.easemob_kefu_name && session.user.easemob_kefu_pwd)){
            EasemobChat.chatLogout(async (resStr)=>{
                if(resStr == 'success'){
                    await api.post("/housekeeper/logout",{phone: session.user.phone});
                    let {actions, dispatch} = this.props;
                    this.setState({loadingShow:false});
                    dispatch(actions.session.clear_session());
                }else{
                    this.setState({loadingShow:false});
                    dispatch(actions.session.clear_session());
                    this.refs.toast.show("退出失败");
                }
            });
        }else{
            await api.post("/housekeeper/logout",{phone: session.user.phone});
            let {actions, dispatch} = this.props;
            this.setState({loadingShow:false});
            dispatch(actions.session.clear_session());
        }

    }

    componentWillUnmount(){
        this._subcribAccount && this._subcribAccount.remove();
        this._subcribDelivery && this._subcribDelivery.remove();
        this._updateSession && this._updateSession.remove();
        this._updateSignContract && this._updateSignContract.remove();
    }

    async loadDeliveryApproved (){
        let result = await api.post('/delivery/countUnApproveStatus',{});
        if(result){
            this.setState({deliveryCount:result.data})
        }

    }

    async _getNotApprovedCount(){
        let count_data = await api.post('/housekeeper/notapprovedcount', {});
        if(count_data){
            this.setState({
                notapprovedcount: count_data.data
            });
        }
    }

    async _getOrderSummary(){
        let { session } = this.props;
        if(session && session.user){
            let res = await api.post("/order/ordersummary",{user_id: session.user.id});
            let sumres = await api.post("/card/withdrawcount",{});
            //余额加上了商品金额
            if(res.data && sumres){
                this.setState({
                    balance: res.data.order_reward + res.data.order_obj_price - sumres.data,
                    order_count: res.data.order_count,
                    order_reward: res.data.order_reward,
                    order_obj_price: res.data.order_obj_price,
                });
            }
        }
    }

    async _getShopBalance(){
        let shopSumres = await api.post("/housekeeper/shopsKeeperBalance",{});
        if (shopSumres.cd != 0) {
            this.refs.toast.show(shopSumres.msg);
            return;
        }
        this.setState({
            shopAllBalance:shopSumres.data.allBalance,
            shopWithdrawBalance:shopSumres.data.withdrawBalance,
        })
    }

    async _getContractInfo(){
        let result  = await api.post("/housekeeper/getSignContractMessage",{});
        
        console.log('/housekeeper/getSignContractMessage------',result);
        if (result.cd != 0) {
            this.refs.toast.show(result.msg);
            return;
        }
        let contractInfo = result.data;
        let {showShopContractDialog} = this.state;
        if (contractInfo && contractInfo.shopContract && contractInfo.shopContract.isFirst == 1) {
            showShopContractDialog = true;
        }else{
            showShopContractDialog = false;
        }
        this.setState({
            contractInfo,
            showShopContractDialog,
        })
    }

    async _getHKSummary(){
        let res = await api.post("/order/getOwnerServiceSummary",{page:1, pagesize: 5});
        if(res.cd == 0){

            this.setState({
                reward_score: res.data.reward_score,
                rank: res.data.rank,
                flag_ardour: res.data.flag_ardour,
                flag_capable: res.data.flag_capable,
                flag_witty: res.data.flag_witty,
                flag_intimate: res.data.flag_intimate
            });
        }
    }

    async _getShowingTab(){
        let res = await api.post("/config/getProductButtonBySource",{});
        let showTaskCenter=false;//任务中心
        let showMyOwner=false;//我的业主
        let showMyBalance=false;//我的余额
        let showDeliveryApply=false;//交付审核
        let showMyBankCard=false;//我的银行
        if (res.cd == 0 && res.data != null) {
            for (var i = 0; i < res.data.length; i++) {
                switch(res.data[i].key) {
                    case "taskCenter":
                        showTaskCenter = true;
                        break;
                    case "myOwner":
                        showMyOwner = true;
                        break;
                    case "myBalance":
                        showMyBalance = true;
                        break;
                    case "deliveryApply":
                        showDeliveryApply = true;
                        break;
                    case "myBankCard":
                        showMyBankCard = true;
                        break;
                }
            }
        }else{
            console.log('test',res.msg);
        }
        this.setState({
            showTaskCenter,//任务中心
            showMyOwner,//我的业主
            showMyBalance,//我的余额
            showDeliveryApply,//交付审核
            showMyBankCard,//我的银行卡
        })

    }

    getScrollResponder() {
      return this._scrollView.getScrollResponder();
    }

    setNativeProps(props) {
      this._scrollView.setNativeProps(props);
    }

    _sellRecord(page){
        let {navigator} = this.props;

        navigator.push({
            title: "到店销售记录",
            backButtonTitle:'',
            screen: 'housekeeperapp.sellrecordinfo',
            passProps: {
                // orderId
                page: page
            },
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarTextColor: 'white',
                navBarButtonColor: 'white',
                navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }
        });
    }

    _addTask(page){
        let {navigator} = this.props;

        navigator.push({
            title: "任务中心",
            backButtonTitle:'',
			screen: 'housekeeperapp.orderfinished',
			passProps: {
				// orderId
                page: page
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }
		});
    }

    _addUser(){
        let {navigator} = this.props;

        navigator.push({
            title: "我的业主",
            backButtonTitle:'',
			screen: 'housekeeperapp.ownerinfonew',
			passProps: {
				// orderId
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }
		});
    }

    _addMyMoney(){
        let {navigator} = this.props;
        navigator.push({
            title: "我的余额",
            backButtonTitle:'',
			screen: 'housekeeperapp.mymoney',
			passProps: {
				order_reward: this.state.order_reward,
                order_obj_price: this.state.order_obj_price
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }
		});
    }

    _addSetting(){
        let {navigator} = this.props;
        navigator.push({
            title: "账户设置",
            backButtonTitle:'',
			screen: 'housekeeperapp.settingindex',
			passProps: {
				// orderId
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }
		});
    }

    _addMsgSetting(){
        Navigation.startMsgSettingActivity();
    }
    _addAboutKeeper(){
        let {navigator} = this.props;
        navigator.push({
            title: "关于管家来了",
            backButtonTitle:'',
			screen: 'housekeeperapp.aboutkeeper',
			passProps: {
				// orderId
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }

		});

    }

    _addMyCard(){
        let {navigator} = this.props;
        navigator.push({
            title: "我的银行卡",
            backButtonTitle:'',
			screen: 'housekeeperapp.cardIndex',
			passProps: {
				// orderId
			},
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }

		});
    }

    _addHKInfo(){
        let {navigator, session} = this.props;
        let hk_role = session.user.role;
        let village = session.user.village;
        if(hk_role == 1 && !village){
            return;
        }

        navigator.push({
            title: "个人信息",
            backButtonTitle:'',
            screen: 'housekeeperapp.hkinfo',
            passProps: {
                // orderId
            },
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
                navBarButtonColor: 'white',
                navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }

        });
    }

    //跳转到交付审核列表页面
    _addDelivery(){
        let {navigator} = this.props;
        navigator.push({
            title: "交付审核",
            backButtonTitle:'',
            screen: 'housekeeperapp.deliverylist',
            passProps: {
                // orderId
            },
            navigatorStyle:{
                navBarHidden: false,
                tabBarHidden: true,
                navBarNoBorder: true,
                navBarTextColor: 'white',
                navBarButtonColor: 'white',
                navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                topBarElevationShadowEnabled:false,
                navBarTitleTextCentered: true
            },
            navigatorButtons: {
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ]
            }

        });
    }

    _addOrderReward(){
        Navigation.startOrderRewardRulesActivity();
        this.setState({
            isClickOrderRewardTab:true
        })
        NativeModules.SharedPreferences.saveBoolean("isClickOrderRewardTab",{"isClickOrderRewardTab":true})

    }

    //打开扫描二维码的activity
    _startScan(){

        Navigation.startScanQRCodeActivity();
    }

    _statrChangeServiceStatus(){
        let {session} = this.props;
        if (session && session.user) {
            let {isRest} = session.user;
            Navigation.startChangeStatusActivity({"isRest":isRest});
        }
        
    }

    _startMySignContractActivity(){

        let {contractInfo} = this.state;
        if (contractInfo && contractInfo.privilegeShops) {
            Navigation.startMySignContractActivity({"status":contractInfo.privilegeShops.contractStatus,"shopId":contractInfo.privilegeShops.id});
            this.setState({
                showShopContractDialog:false,
            })
        }
        
    }

    _idCardVerify(){
        Navigation.startIDCardVerifyActivity();
    }

    closeModal = () => {
        this.setState({showModal:false})
        console.log('close Modal')
    }

    closeOrderRewardDialog = ()=>{
        this.setState({showOrderRewardDialog:false})
        NativeModules.SharedPreferences.saveBoolean("isShowRecordDialog",{"isShowRecordDialog":true})
        console.log('close Modal')
    }

    goToRulePage = () =>{
        console.log('test',"dddddd");
        this.setState({showOrderRewardDialog:false})
        NativeModules.SharedPreferences.saveBoolean("isShowRecordDialog",{"isShowRecordDialog":true})
        Navigation.startOrderRewardRulesActivity();

    }

    _closeShopContractDialog(){
        this.setState({
            showShopContractDialog:false,
        })
    }

    _renderSignEntry(contractInfo){
        let {privilegeShops,shopContract} = contractInfo;
        if (privilegeShops) {
            let status = privilegeShops.contractStatus;
            if (status == "UNSIGNED") {//未签约
                return (<Text style={{color:'#EA5404',fontSize:13}}>（未签约）</Text>)
            }else if (status == "SIGNED") {//已签约
                let startTime = shopContract.contractStartTime;
                let endTime = shopContract.contractEndTime;
                let period = "（"+startTime+"至"+endTime+"）";
                return (<Text style={{color:'#7B7B7B',fontSize:13}}>{period}</Text>)
            }
        }
        return null
    }

    render() {

        let { scrollY, order_count, order_reward, balance, reward_score, rank, flag_ardour, flag_capable, flag_witty, flag_intimate ,
                showTaskCenter,
                showMyOwner,
                showMyBalance,
                showDeliveryApply,
                showMyBankCard,
                shopAllBalance,
                contractInfo,
            } = this.state;

        let { session } = this.props;
        if(!session){
            return null;
        }

        //设置名称
        let hk_name = session.user.keeper_name;
        let hk_role = session.user.role;
        let village = session.user.village;
        let productKey = session.user.productKey;
        let isRest = session.user.isRest;

        if(hk_name.length > 10){
            hk_name = session.user.keeper_name.substring(0,10) + '...';
        }

        return (
            <View style={styles.container}>
                <Animated.View
                    style={[styles.headContainer, {
                        height: windowHeight,
                        transform: [{
                            translateY: scrollY.interpolate({
                                inputRange: [ -windowHeight, 0, windowHeight],
                                outputRange: [windowHeight/2, 0, -windowHeight/3]
                            })
                        },{
                            scale: scrollY.interpolate({
                                inputRange: [ -windowHeight, 0, windowHeight],
                                outputRange: [2, 1, 1]
                            })
                        }]
                    }]}>


                        <Image style={styles.headBg} source={require('../../../img/hk_account_head_bg_v2.png')}/>

                </Animated.View>

                    

                <ScrollView
                    ref={component => { this._scrollView = component; }}
                    style={styles.scrollContainer}
                    onScroll={Animated.event(
                      [{ nativeEvent: { contentOffset: { y: this.state.scrollY }}}]
                    )}
                    scrollEventThrottle={16}>
                    <Animated.View style={{
                        position: 'relative',
                        backgroundColor: 'transparent',
                        overflow: 'visible',
                        height: windowHeight,
                        opacity: scrollY.interpolate({
                            inputRange: [-windowHeight, 0, windowHeight / 1.2],
                            outputRange: [1, 1, 0]
                        }),
                    }}>
                        <Touch activeOpacity={hk_role==1?1:0.7} style={styles.headTextBtn} onPress={this._addHKInfo.bind(this)}>
                            <Text style={styles.headText}>{hk_name} {hk_role==1?'':'>'}</Text>
                        </Touch>
                        {session.user.isShop == 1?
                            <Touch onPress={this._startScan.bind(this)} style={[styles.scanButtonImage]}>
                                <Image source={require('../../../img/scan_button_icon.png')}/>
                                <Text style={{fontSize:14,color:'#fff',marginLeft: 4}}>扫一扫</Text>
                            </Touch>
                            :
                            null
                        }
                        
                    </Animated.View>
                    <View style={styles.headImageContainer}>
                        <Touch activeOpacity={hk_role==1?1:0.7} onPress={this._addHKInfo.bind(this)}>
                            <Image style={styles.headImage} source={{uri: session.user.keeper_head}}/>
                        </Touch>
                    </View>
                    <View style={styles.scrollContent}>
                        {
                            hk_role==0 || hk_role==2 || (hk_role == 1 && village)?
                                <View style={styles.overallContainer}>
                                    <View style={styles.overallDetail}>
                                        {
                                            session.user.isShop == 1?
                                                null
                                            :
                                                <Text style={[styles.overallText,{marginRight: 15}]}>{productKey == 'HeChang'?`全部管家排名：`:`当月排名：`}
                                                    <Text style={styles.sprText}>
                                                        {
                                                            rank && rank.split('/')[0]!='0'?
                                                                rank.split('/')[0]
                                                            :
                                                                '--'
                                                        }
                                                    </Text>/
                                                        {
                                                            rank?
                                                                rank.split('/')[1]
                                                            :
                                                                '--'
                                                        }
                                                </Text>
                                        }
                                        
                                        <Text style={[styles.overallText]}>服务评分：<Text style={styles.sprText}>{reward_score?reward_score+'星':'--'}</Text></Text>
                                    </View>
                                    <View style={styles.tagContainer}>
                                        <Text style={styles.notActiveText}>热情 {flag_ardour>999999?'999999+':flag_ardour}</Text>
                                        <Text style={styles.notActiveText}>干练 {flag_capable>999999?'999999+':flag_capable}</Text>
                                        <Text style={styles.notActiveText}>机智 {flag_witty>999999?'999999+':flag_witty}</Text>
                                        <Text style={styles.notActiveText}>贴心 {flag_intimate>999999?'999999+':flag_intimate}</Text>
                                    </View>
                                </View>
                            :
                                <View style={[styles.overallContainer,{height: 50}]}></View>
                        }

                        {
                            hk_role==0 || hk_role==2 || (hk_role == 1 && village)?
                                <View style={styles.leftrightInfo}>
                                    <Touch style={styles.moneyLeftInfo} onPress={this._addTask.bind(this,1)}>
                                        <Text style={styles.numStyle}>{order_count}<Text style={styles.unitStyle}>笔</Text></Text>
                                        <Text style={styles.subStyle}>完成订单</Text>
                                    </Touch>
                                    <Touch style={styles.moneyRightInfo} onPress={this._addMyMoney.bind(this)}>
                                        <Text style={styles.numStyle}>{
                                            session.user.isShop == 1?
                                            shopAllBalance?shopAllBalance.toFixed(2):'0.00'
                                            :
                                            `${balance.toFixed(2)}`
                                        }<Text style={styles.unitStyle}>元</Text></Text>
                                        <Text style={styles.subStyle}>我的余额</Text>
                                    </Touch>
                                </View>
                            :
                                null
                        }

                        <View style={styles.toolsContainer}>

                            {
                                session.user.isShop == 1 && (contractInfo && contractInfo.privilegeShops && contractInfo.privilegeShops.contractStatus != 'NOT_GENERATE')?
                                    <Touch onPress={this._startMySignContractActivity.bind(this)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_he_tong_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>我的签约{this._renderSignEntry(contractInfo)}
                                        </Text>
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    null
                            }
                            {
                                hk_role == 1?
                                    null
                                :
                                    session.user.isShop == 1?
                                        null
                                    :
                                        <Touch onPress={this._statrChangeServiceStatus.bind(this)} style={styles.addBtn}>
                                            <Image source={require('../../../img/service_status_icon.png')} style={styles.leftImage}/>
                                            <Text style={styles.addText}>服务状态{isRest == 1?<Text style={{fontSize:13}}>（休息中）</Text>:<Text style={{fontSize:13}}>（服务中）</Text>}</Text>
                                            <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                        </Touch>
                            }
                            <Touch onPress={this._addTask.bind(this,0)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_task_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>任务中心</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>
                                
                            {
                                showMyOwner?
                                    <Touch onPress={this._addUser.bind(this)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_account_user_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>我的业主</Text>
                                        {this.state.notapprovedcount?<View style={styles.markStyle}><Text style={styles.markTextStyle}>{this.state.notapprovedcount>99?"99+":this.state.notapprovedcount}</Text></View>:null}
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    null
                            }
                            {
                                showMyBalance?
                                    <Touch onPress={this._addMyMoney.bind(this)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_account_money_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>我的余额</Text>
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    hk_role == 1 && village?
                                        <Touch onPress={this._addMyMoney.bind(this)} style={styles.addBtn}>
                                            <Image source={require('../../../img/hk_account_money_icon.png')} style={styles.leftImage}/>
                                            <Text style={styles.addText}>我的余额</Text>
                                            <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                        </Touch>
                                    :
                                        null
                            }
                            {
                                showDeliveryApply?
                                    <Touch onPress={this._addDelivery.bind(this)} style={[styles.addBtn]}>
                                        <Image source={require('../../../img/hk_account_delivery_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>交付审核</Text>
                                        {this.state.deliveryCount?<View style={styles.markStyle}><Text style={styles.markTextStyle}>{this.state.deliveryCount>99?"99+":this.state.deliveryCount}</Text></View>:null}
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    null
                            }
                            {
                                showMyBankCard?
                                    <Touch onPress={this._addMyCard.bind(this)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_account_card_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>我的银行卡</Text>
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    hk_role == 1 && village?
                                    <Touch onPress={this._addMyCard.bind(this)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_account_card_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>我的银行卡</Text>
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                    :
                                    null
                            }
                            
                            
                            {
                                session.user.isShop == 1?
                                    <Touch onPress={this._sellRecord.bind(this,0)} style={styles.addBtn}>
                                        <Image source={require('../../../img/hk_account_sell_record_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>到店销售记录</Text>
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    null

                            }
                            

                            {/*<Touch onPress={this._addTask.bind(this,0)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_task_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>任务中心</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>*/}


                            {/*{hk_role==0?<Touch onPress={this._addUser.bind(this)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_user_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>我的业主</Text>
                                {this.state.notapprovedcount?<View style={styles.markStyle}><Text style={styles.markTextStyle}>{this.state.notapprovedcount>99?"99+":this.state.notapprovedcount}</Text></View>:null}
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>:null}*/}

                            {/*{hk_role==0 || hk_role==2?<Touch onPress={this._addMyMoney.bind(this)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_money_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>我的余额</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>:null}*/}

                            {/*{hk_role==0?<Touch onPress={this._addDelivery.bind(this)} style={[styles.addBtn]}>
                                <Image source={require('../../../img/hk_account_delivery_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>交付审核</Text>
                                {this.state.deliveryCount?<View style={styles.markStyle}><Text style={styles.markTextStyle}>{this.state.deliveryCount>99?"99+":this.state.deliveryCount}</Text></View>:null}
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>:null}*/}

                            {/*{hk_role==0 || hk_role==2?<Touch onPress={this._addMyCard.bind(this)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_card_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>我的银行卡</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>:null}*/}
                            {productKey == "HuLiZhan"?
                                <Touch onPress={this._idCardVerify.bind(this)} style={[styles.addBtn]}>
                                    <Image source={require('../../../img/id_card_icon.png')} style={[styles.leftImage,{width:15,height:10}]}/>
                                    <Text style={styles.addText}>身份证认证</Text>
                                    <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                </Touch>
                            :
                            null}
                            

                            <Touch onPress={this._addSetting.bind(this)} style={styles.addBtn}>
                                <Image source={require('../../../img/hk_account_setting_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>账户设置</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>


                            <Touch onPress={this._addMsgSetting.bind(this)} style={[styles.addBtn]}>
                                <Image source={require('../../../img/hk_account_msg_icon.png')} style={styles.leftImage}/>
                                <Text style={styles.addText}>消息设置</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>

                            {/*=====去除超极管家订单奖励{
                                (hk_role == 0 || hk_role == 2 || (hk_role == 1 && village)) && session.user.isShop != 1 && session.user.productKey == "HeChang" ?
                                    <Touch onPress={this._addOrderReward.bind(this)} style={[styles.addBtn]}>
                                        <Image source={require('../../../img/hk_account_order_reward_icon.png')} style={styles.leftImage}/>
                                        <Text style={styles.addText}>{hk_role == 0?"超级管家订单奖励":"管家订单奖励"}</Text>
                                        {this.state.isClickOrderRewardTab?null:<View style={styles.littleMarkStyle}></View>}
                                        <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                    </Touch>
                                :
                                    null
                            }*/}

                            

                            <Touch onPress={this._addAboutKeeper.bind(this)} style={[styles.addBtn,{borderBottomWidth:0}]}>
                                <Image source={require('../../../img/info.png')} style={[styles.leftImage,{width:15,height:15}]}/>
                                <Text style={styles.addText}>关于管家来了</Text>
                                <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                            </Touch>

                            
                            
                            <VersionModal showModal={this.state.showModal} lastVersionInfo={this.state.lastVersionInfo} closeModal={this.closeModal}/>
                            <ShopContractDialog showModal={this.state.showShopContractDialog} onClickCancelButton={this._closeShopContractDialog.bind(this)} onClickConfirmButton={this._startMySignContractActivity.bind(this)}/>
                            <OrderRewardDialog showModal={this.state.showOrderRewardDialog} closeModal={this.closeOrderRewardDialog} goToRulePage={this.goToRulePage}/>
                             


                        </View>
                            
                    </View>
                </ScrollView>
                <LoadingTip show={this.state.loadingShow}/>
            </View>
        );
    }
}

var connectHelper = require('../../services/connectHelper');
Account = connectHelper(state => state)(Account);

module.exports = Account;
